﻿using SuperMap.Data;
using SuperMap.Realspace;
using System;
using System.Collections.Generic;
using WeifenLuo.WinFormsUI.Docking;
using Ycjw.PipeLine.Map.Basic.Conditions;
using Ycjw.PipeLine.Map.Basic.SuperMap;

namespace Ycjw.PipeLine.Map.Tools.Conditions
{
    class GJSearcher : ConditionPanel
    {
        private Sunny.UI.UIGroupBox uiGroupBoxgxlx;
        private Sunny.UI.UIGroupBox uiGroupBoxgxcs;
        private Sunny.UI.UILabel uiLabel2;
        private Sunny.UI.UILabel uiLabel1;
        private Sunny.UI.UIDoubleUpDown uiDoubleUpDowngxgj;
        private LayerWithDataListPanel LayerWithDataListPanel;
        public GJSearcher() : base()
        {
            InitializeComponent();
        }
        protected override void OnLoad(EventArgs e)
        {
            LayerWithDataListPanel = new LayerWithDataListPanel()
            {
                Dock = System.Windows.Forms.DockStyle.Fill
            };
            Scene scene = this.Scene;
            if (scene == null) return;
            LayerWithDataListPanel.Init(scene);
            //LayerWithDataListPanel.LoadToVector();
            var types = new List<DatasetType>()
            {
                DatasetType.Line,
                DatasetType.Line3D ,
                DatasetType.Network,
                DatasetType.Network3D
            };
            LayerWithDataListPanel.LoadTo(types);
            this.uiGroupBoxgxlx.Controls.Add(LayerWithDataListPanel);
            uiGroupBoxgxlx.Width = this.Width / 2;
            /*
             Scene scene = null;
             if (BaseConditions.ContainsKey("Scene"))
             {
                 scene = BaseConditions["Scene"] as Scene;
             }
             if (scene == null) return;
             var lyrInScene = scene.Layers;
             this.groupBoxgjcx.Controls.Clear();
             var positionTop = 20;
             foreach (Layer3D lyr in lyrInScene)
             {
                 RadioButton rb = new RadioButton();
                 rb.Text = lyr.Caption;
                 rb.Name = lyr.Name;
                 rb.AutoSize = true;
                 rb.Location = new System.Drawing.Point(10, positionTop);
                 positionTop += 24;
                 this.groupBoxgjcx.Controls.Add(rb);
             }
           */
        }

        public override bool ConditionValid()
        {
            var dataset = LayerWithDataListPanel.SelectLayer3DDataset;
            if (dataset == null)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层不是矢量图层");
                return false;
            }

            return base.ConditionValid();
        }
        public override object Do(DockPanel dockPanel = null)
        {
            var dataset = LayerWithDataListPanel.SelectLayer3DDataset;
            if (dataset == null)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层不是矢量图层");
                return null;
            }

            var dataSetVector = dataset.Dataset as SuperMap.Data.DatasetVector;
            bool hasGJField = false;
            for (int i = 0; i < dataSetVector.FieldInfos.Count; i++)
            {
                if (dataSetVector.FieldInfos[i].Name == "管径")
                {
                    hasGJField = true;
                    break;
                }
            }
            if (!hasGJField)
            {
                Sunny.UI.UIMessageTip.ShowError("选择的图层没有管径信息");
                return null;
            }
            DatasetVectorEx dvEx = new DatasetVectorEx(dataset.Name)
            {
                DatasetVector = dataSetVector
            };
            return dvEx.Query("管径 >= " + this.uiDoubleUpDowngxgj.Value);

            //this.ShowResult(dat, dockPanel, DockState.DockBottom, "按管径查询-执行结果");
            //base.Do(dockPanel);
        }

        private void InitializeComponent()
        {
            this.uiGroupBoxgxlx = new Sunny.UI.UIGroupBox();
            this.uiGroupBoxgxcs = new Sunny.UI.UIGroupBox();
            this.uiLabel2 = new Sunny.UI.UILabel();
            this.uiLabel1 = new Sunny.UI.UILabel();
            this.uiDoubleUpDowngxgj = new Sunny.UI.UIDoubleUpDown();
            this.uiGroupBoxgxcs.SuspendLayout();
            this.SuspendLayout();
            // 
            // uiGroupBoxgxlx
            // 
            this.uiGroupBoxgxlx.Dock = System.Windows.Forms.DockStyle.Left;
            this.uiGroupBoxgxlx.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBoxgxlx.Location = new System.Drawing.Point(0, 0);
            this.uiGroupBoxgxlx.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBoxgxlx.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBoxgxlx.Name = "uiGroupBoxgxlx";
            this.uiGroupBoxgxlx.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBoxgxlx.Size = new System.Drawing.Size(213, 316);
            this.uiGroupBoxgxlx.TabIndex = 0;
            this.uiGroupBoxgxlx.Text = "管线类型";
            // 
            // uiGroupBoxgxcs
            // 
            this.uiGroupBoxgxcs.Controls.Add(this.uiLabel2);
            this.uiGroupBoxgxcs.Controls.Add(this.uiLabel1);
            this.uiGroupBoxgxcs.Controls.Add(this.uiDoubleUpDowngxgj);
            this.uiGroupBoxgxcs.Dock = System.Windows.Forms.DockStyle.Fill;
            this.uiGroupBoxgxcs.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiGroupBoxgxcs.Location = new System.Drawing.Point(213, 0);
            this.uiGroupBoxgxcs.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiGroupBoxgxcs.MinimumSize = new System.Drawing.Size(1, 1);
            this.uiGroupBoxgxcs.Name = "uiGroupBoxgxcs";
            this.uiGroupBoxgxcs.Padding = new System.Windows.Forms.Padding(0, 32, 0, 0);
            this.uiGroupBoxgxcs.Size = new System.Drawing.Size(244, 316);
            this.uiGroupBoxgxcs.TabIndex = 1;
            this.uiGroupBoxgxcs.Text = "查询参数";
            // 
            // uiLabel2
            // 
            this.uiLabel2.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiLabel2.Location = new System.Drawing.Point(192, 60);
            this.uiLabel2.Name = "uiLabel2";
            this.uiLabel2.Size = new System.Drawing.Size(57, 29);
            this.uiLabel2.TabIndex = 2;
            this.uiLabel2.Text = "毫米";
            this.uiLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // uiLabel1
            // 
            this.uiLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiLabel1.Location = new System.Drawing.Point(7, 32);
            this.uiLabel1.Name = "uiLabel1";
            this.uiLabel1.Size = new System.Drawing.Size(100, 23);
            this.uiLabel1.TabIndex = 1;
            this.uiLabel1.Text = "管线管径：";
            this.uiLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // uiDoubleUpDowngxgj
            // 
            this.uiDoubleUpDowngxgj.Font = new System.Drawing.Font("微软雅黑", 12F);
            this.uiDoubleUpDowngxgj.Location = new System.Drawing.Point(8, 60);
            this.uiDoubleUpDowngxgj.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
            this.uiDoubleUpDowngxgj.MinimumSize = new System.Drawing.Size(100, 0);
            this.uiDoubleUpDowngxgj.Name = "uiDoubleUpDowngxgj";
            this.uiDoubleUpDowngxgj.Size = new System.Drawing.Size(177, 29);
            this.uiDoubleUpDowngxgj.Step = 1D;
            this.uiDoubleUpDowngxgj.TabIndex = 0;
            this.uiDoubleUpDowngxgj.Text = "uiDoubleUpDown1";
            this.uiDoubleUpDowngxgj.Value = 0D;
            // 
            // GJSearcher
            // 
            this.Controls.Add(this.uiGroupBoxgxcs);
            this.Controls.Add(this.uiGroupBoxgxlx);
            this.Name = "GJSearcher";
            this.Size = new System.Drawing.Size(457, 316);
            this.uiGroupBoxgxcs.ResumeLayout(false);
            this.ResumeLayout(false);

        }
    }
}
